import mySqlFunc
from config import *
import myLogger

sqlConn = mySqlFunc.MysqlConnector(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE,
                                   myLogger.initLogger("./log/sql.txt"))

sqlConn.Execute(f"DROP TABLE IF EXISTS {SESSION_TABLE}")
sqlConn.Execute(f"""CREATE TABLE IF NOT EXISTS `{SESSION_TABLE}`(
   `session_id` CHAR(32) NOT NULL,
   `uid` INT UNSIGNED NOT NULL,
   `ip` VARCHAR(20) NOT NULL,
   `expire_time` DATETIME(0) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
""")

sqlConn.Execute(f"DROP TABLE IF EXISTS {USER_TABLE}")
sqlConn.Execute(f"""CREATE TABLE IF NOT EXISTS `{USER_TABLE}`(
   `uid` INT UNSIGNED NOT NULL,
   `username` VARCHAR(20) NOT NULL ,
   `password` VARCHAR(20) NOT NULL ,
   `priority` INT UNSIGNED NOT NULL ,
   `balance` INT UNSIGNED NOT NULL ,
   PRIMARY KEY ( `uid` )
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
""")

sqlConn.Insert(USER_TABLE,
               {"uid": 1, "username": "admin", "password": "1", "priority": PRIORITY_CLERKS, "balance": 10000})
